import { login } from "@/api/user"
import  storage from '@/util/storage'
const user = {
    state: {
        userName:'',
        nickName:'',
        token:'',
    },
    getters:{   
    },
    mutations: {
        SAVE_USERNAME(state,userName){
            state.userName = userName;

        },
        SAVE_NICKNAME(state,nickName){
            state.nickName = nickName;
            
        },
        SAVE_TOKEN(state,token){
            state.token = token;
            
        }
    },
    actions: {
        LOGIN({ commit },user){
            login(user).then(res => {
                // 需要将获取到的数据保存起来
                commit("SAVE_USERNAME",res.data.ydlUser.userName),
                commit("SAVE_NICKNAME",res.data.ydlUser.nickName),
                commit("SAVE_TOKEN",res.data.token)
                storage.saveSessionObject("loginUser",res.data)
            })
        }
    }
}

export default user
